package com.sijibao.gather.admin.kafka;

import java.util.HashMap;
import java.util.Map;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("kafkaAdminAdapter")
public class KafkaAdminAdapter
{
	@Autowired
	private KafkaAdminConfig kafkaAdminConfig;

	private AdminClient adminClient;

	private synchronized void init()
	{
		Map<String, Object> configs = new HashMap<String, Object>();
		configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,
				kafkaAdminConfig.getBootstrapServers());
		configs.put(AdminClientConfig.CLIENT_ID_CONFIG, kafkaAdminConfig.getClientId());
		adminClient = AdminClient.create(configs);
	}

	public AdminClient getAdminClient()
	{
		if (adminClient == null)
		{
			init();
		}
		return adminClient;
	}

	

	public KafkaAdminConfig getKafkaAdminConfig()
	{
		return kafkaAdminConfig;
	}

	

}
